package br.com.ustore.agent.backup.producer;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import br.com.ustore.agent.backup.domain.BackupData;

public class AgentBackupSender {
	
	@Autowired
	private JmsTemplate jmsTemplate;
	
	public void sendData(final BackupData backupsData){
		jmsTemplate.send(
		new MessageCreator() {
	      public Message createMessage(Session session) throws JMSException {
	           MapMessage mapMessage = session.createMapMessage();
	           mapMessage.setLong("path_id", backupsData.getPath_id());
	           mapMessage.setLong("start_time", backupsData.getStart_time());
	           mapMessage.setLong("end_time", backupsData.getEnd_time());
	           mapMessage.setInt("numberOfPeers", backupsData.getNumberOfPeers());
	           mapMessage.setLong("fileLength", backupsData.getFileLength());
	           return mapMessage;
	      }
	    }
		);
	}
}
